package application.models.collections;

import java.io.IOException;
import java.util.Iterator;
import application.models.datalayer.DataCondition;
import application.models.exceptions.InvalidAttributeException;
import application.models.Observable;

/**
 * A collection of some model, M.
 * Collections are generally a set of model objects matching some attribute conditions.
 * The content of the collection changes as the loaded models of the application changes state.
 * The content of a collection may therefore change between load() calls
 * 
 * @author Philip Rasmussen & Morten Therkildsen
 *
 * @param <M>	What model the implementor is a collection of
 */
public interface Collection<M> extends Iterable<M>, Observable {
	
	/**
	 * Loads all models of its kind filtered by previously set filters
	 * If no filters are set, all models will be loaded
	 * 
	 * @throws IOException	if the collection failed to load its data
	 */
	public void load() throws IOException;
	
	/**
	 * Adds a filter to the collection.
	 * 
	 * @param condition		A condition for one of the attributes of the entity
	 * 
	 * @throws InvalidAttributeException if the model does not support the attribute used by the condition
	 */
	public void addFilter(DataCondition filter) throws InvalidAttributeException;
	
	/**
	 * Removes a filter from the collection.
	 * If the filter is not present, the method does nothing
	 * 
	 * @param condition		A condition for one of the attributes of the entity that is to be removed
	 */
	public void removeFilter(DataCondition filter);
	
	/**
	 * Returns all currently set filters
	 * 
	 * @return	An array of the set filters
	 */
	public DataCondition[] getFilters();
	
	/**
	 * Returns all filters that was set prior to the latest call to load load()
	 * 
	 * @return	An array of the applied filters
	 */
	public DataCondition[] getAppliedFilters();
	
	/**
	 * Used for iteration
	 * 
	 * @return an iterator which can used to iterate over the collection
	 */
	public Iterator<M> iterator();
	
	/**
	 * How many models the collection contains
	 * 
	 * @return the number of models in the collection
	 */
	public int size();
}
